<?php
namespace ImiApp\WebSocketServer\Controller;

use Imi\ConnectContext;
use Imi\Aop\Annotation\Inject;
use Imi\Bean\Annotation\ClassEventListener;
use Imi\Server\Event\Param\CloseEventParam;
use Imi\Server\Event\Listener\ICloseEventListener;


use Imi\Controller\WebSocketController;
use Imi\Server\Route\Annotation\WebSocket\WSController;

/**
 * @ClassEventListener(className="Imi\Server\WebSocket\Server", eventName="close")
 */
class In implements ICloseEventListener
{
    // /**
    //  * @Inject("RoomLogic")
    //  *
    //  * @var \ImiApp\Module\Gobang\Logic\RoomLogic
    //  */
    // protected $roomLogic;

    /**
     * 事件处理方法
     * @param CloseEventParam $e
     * @return void
     */
    public function handle(CloseEventParam $e)
    {
        var_dump(date('Y-m-d H:i:s'));
        var_dump($e->fd);
        // var_dump($e);
        $group = '22_11';
        
        // $thiss = new WebSocketController;
        // $num = $e->server->getGroup($group)->count();
        $e->server->groupCall($group, 'push', ConnectContext::get('username').date('Y-m-d H:i:s').'离线');//ConnectContext::get('username')
        // /** @var \Imi\Server\Http\Route\RouteResult $httpRouteResult */
        // $httpRouteResult = ConnectContext::get('httpRouteResult');
        // if('/ws' === ($httpRouteResult->routeItem->annotation->url ?? null))
        // {
        //     $memberId = ConnectContext::get('memberId');
        //     if($memberId)
        //     {
        //         $this->roomLogic->onMemberClose($memberId);
        //     }
        // }
    }

}
